 <%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<script type="text/javascript">
	$(function(){
		$("#formID").validationEngine({
			showOnMouseOver : true
		});
		var moduleTree=$("#moduleTree").tree({
			checkbox : true,
			url : "${ctx}/roleInfoController.do?method=getModuleTree&flag=operate&roleid=${roleInfo.roleid}",
			animate : true
		});
		/* var dataTree=$("#dataTree").tree({
			checkbox : true,
			url : "${ctx}/roleInfoController.do?method=getModuleTree&flag=data&roleid=${roleInfo.roleid}",
			animate : true
		}); */
		$("#btn_save").click(function(){
			var valid = $("#formID").validationEngine('validate');
			if(!valid)
				return;
			var modules = moduleTree.tree("getChecked");
			var moduleSet = [];
			for ( var i = 0; i < modules.length; i++) {
				var attr = modules[i].attributes || {};
				var obj = decode(attr);
				if (!obj.moduleid) continue; 
				moduleSet.push((obj.operid || "") + "," + (obj.moduleid || ""));
			}
			moduleSet = moduleSet.join(";");
			/* var datas = dataTree.tree("getChecked");
			var dataSet = [];
			for ( var i = 0; i < datas.length; i++) {
				var attr = datas[i].attributes || {};
				var obj = decode(attr);
				if (!obj.moduleid) continue; 
				dataSet.push((obj.dataid || "") + "," + (obj.moduleid || ""));
			}
			dataSet = dataSet.join(";"); */
			var params = $("form[name=roleInfoForm]").getFormParams();
			params["moduleSet"] = moduleSet;
			/* params["dataSet"] = dataSet; */
			$.post("${ctx}/roleInfoController.do?method=save", params, function(data, status) {
				win.window("close");
				if (status == "success") {
					grid.datagrid("reload");
					showTip(alertinfo+"成功");
				} else {
					showTip(alertinfo+"失败");
				}
			}, "json");
		});
		$("#btn_back").click(function(){
			win.window("close");
		});
		fit("#rolecontainer");
	});
	function check(){
		$.ajax({
			type:"post",
			url: "${ctx}/roleInfoController.do?method=check&roleName="+encodeURIComponent(encodeURIComponent($("input[name=roleName]").val())),
			success:function(json){
				if(json){
					var obj = decode(json);
					if (obj.success){
						return true;
					}else{
						alert("该角色名称已存在！");
						$("input[name=roleName]").val("");
					}
				}
			}
		});
	}
</script>
<body>
	<form action="/roleInfoController" method="post" name="roleInfoForm" id="formID" style="width: 100%;height: 100%">
		<c:if test="${roleInfo!=null}">
			<input type="hidden" name="roleid" value="${roleInfo.roleid}"/>
		</c:if>
		<div id="rolecontainer" fit="true" border="false">
			<div region="north" style="height: 100px;" border="false" title="角色信息" collapsible="false">
				<table class="FormView" border="0" cellspacing="1" cellpadding="0">
					<col class="Label" />
					<col class="Data" />
					<col class="Label" />
					<col class="Data" />
					<tr>
						<td>角色名称：</td>
						<td colspan="3"><input type="text" name="roleName" id="roleName" class="validate[required,maxSize[50]] text" value="${roleInfo.roleName}" onchange="check()"/><font color="red">**</font></td>
					</tr>
					<tr> 
						<td>角色描述：</td>
						<td colspan="3"><input type="text" name="remark" id="remark" class="validate[maxSize[100]] text" style="width:80%" value="${roleInfo.remark}"/></td> 
					</tr>
				</table>
			</div>
			<div region="center"  title="操作权限">
				<ul id="moduleTree"></ul>
			</div>
			<!-- <div region="center" title="数据权限">
				<ul id="dataTree"></ul>
			</div> -->
			<div region="south" style="height: 40px;"
				border="false" align="center">
				<div class="tool-btn" id="btn_save">
					<span class="icon-save">&nbsp;</span>
					保存
				</div>
				<div class="tool-btn" id="btn_back">
					<span class="icon-back">&nbsp;</span>
					返回
				</div>
			</div>
		</div>
	</form>
</body>
</html>
